'''
Author: xiaonancheng
Date: 2023-07-01 17:29:03
https://www.cnblogs.com/xiaonancheng
Copyright (c) 2023 by @xiaonancheng, All Rights Reserved. 
'''
from django.shortcuts import render,redirect
import datetime

def index(request):
    name = '用户'
    lis = ['张三', '李四', '王五']
    dic = {'name': '张三', 'sex': '男', 'age': 18}
    num = 30
    stri='abc'
    now=datetime.datetime.now()
    p='sanshldjashdalhsdakshdaljdalsdhladhalkhdaihewoifljwhfospgjsdjsd'

    return render(request, 'index.html', {'mune':'index','p':p,'name': name, 'lis': lis, 'dic': dic, 'num': num,'stri':stri,'now':now})
def info(request):
    print(request.GET,type(request.GET))
    name=request.GET.get('name')
    print(name)

    return render(request,'info.html',{'mune':'info'})

def search(request):#搜索视图函数
    print(request.path)

    if request.method=="GET" and request.GET:
        q=request.GET.get('q')
        
        return render(request,'search.html',{'q':q,'mune':'search'})

    elif request.method=="POST":
        q=request.POST.get('q')
        if q=='123':
            return redirect('/info/')
        q='你输错哦了'
        return render(request,'search.html',{'pq':q,'mune':'search'})

    return render(request,'search.html',{'mune':'search'})

def test(request,name,age):# test 的视图函数
    print(name,age)
    print('name type is ',type(name),'age type is ', type(age))
    return render(request,'info.html')